package com.wondertek.poms.pre.controller;

import java.util.HashMap;
import java.util.Map;
import javax.annotation.Resource;

import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TaskController {

	@Resource
	private ThreadPoolTaskExecutor fastPool;
	@Resource
	private ThreadPoolTaskExecutor slowPool;
	@Resource
	private ThreadPoolTaskExecutor passRulePool;
	
	@GetMapping("/allpool/info")
	public Map<String, Object> all() {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("fastPool", "池队列:" + fastPool.getThreadPoolExecutor().getQueue().size() + 
				"|池任务数:" + fastPool.getThreadPoolExecutor().getTaskCount() + 
				"|池活跃线程数:" + fastPool.getThreadPoolExecutor().getActiveCount()); 
		map.put("slowPool", "池队列:" + slowPool.getThreadPoolExecutor().getQueue().size() + 
				"|池任务数:" + slowPool.getThreadPoolExecutor().getTaskCount() + 
				"|池活跃线程数:" + slowPool.getThreadPoolExecutor().getActiveCount()); 
		map.put("passRulePool", "池队列:" + passRulePool.getThreadPoolExecutor().getQueue().size() + 
				"|池任务数:" + passRulePool.getThreadPoolExecutor().getTaskCount() + 
				"|池活跃线程数:" + passRulePool.getThreadPoolExecutor().getActiveCount()); 
		return map;
	}
	
	@GetMapping("/fastPool/info")
	public Map<String, Object> info() {
		Map<String, Object> map = new HashMap<String, Object>();
		
		map.put("fastPool", "池队列:" + fastPool.getThreadPoolExecutor().getQueue().size() + 
				"|池任务数:" + fastPool.getThreadPoolExecutor().getTaskCount() + 
				"|池活跃线程数:" + fastPool.getThreadPoolExecutor().getActiveCount()); 
		
		return map;
	}
	
	@GetMapping("/slowPool/info")
	public Map<String, Object> info1() {
		Map<String, Object> map = new HashMap<String, Object>();
		
		map.put("slowPool", "池队列:" + slowPool.getThreadPoolExecutor().getQueue().size() + 
				"|池任务数:" + slowPool.getThreadPoolExecutor().getTaskCount() + 
				"|池活跃线程数:" + slowPool.getThreadPoolExecutor().getActiveCount()); 
		
		return map;
	}
	
	@GetMapping("/passRulePool/info")
	public Map<String, Object> info2() {
		Map<String, Object> map = new HashMap<String, Object>();
		
		map.put("passRulePool", "池队列:" + passRulePool.getThreadPoolExecutor().getQueue().size() + 
				"|池任务数:" + passRulePool.getThreadPoolExecutor().getTaskCount() + 
				"|池活跃线程数:" + passRulePool.getThreadPoolExecutor().getActiveCount()); 
		
		return map;
	}
}
